/**
 * 
 */
package com.appspot.newsographer.server.jdo;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import com.appspot.newsographer.client.CountryData;
import com.appspot.newsographer.client.CountryService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * Methods that are define in the {@link CountryService} get implemented here.
 * @author anuradha.uduwage
 *
 */
@SuppressWarnings("serial")
public class CountryServiceImpl extends RemoteServiceServlet implements
		CountryService {

	private static final Logger log = Logger.getLogger(CountryServiceImpl.class.getName());
	/**
	 * 
	 */
	public CountryServiceImpl() {}

	@Override
	public ArrayList<CountryData> getCountryNames(String searchString) {
		
		ArrayList<CountryData> countries = new ArrayList<CountryData>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			String query = "select from " + CountryData.class.getName();
			List<CountryData> entities = (List<CountryData>)pm.newQuery(query).execute();
			for(int i = 0; i < entities.size(); i++) {
				System.out.println(entities.get(i).getCountryName());
				
			}

		} finally {
			pm.close();
		}
		return countries;
	}

}
